//
//  catalogTableView.m
//  PlayShow
//
//  Created by Senela on 2018/4/24.
//  Copyright © 2018年 threeTi. All rights reserved.
//

#import "CatalogTableView.h"
#import "CatalogCell.h"
#import "AppMacro.h"
#import "UIColor+Utils.h"

@implementation CatalogTableView

- (void)initTableView {
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    //注册自定义cell
    [self registerNib:[UINib nibWithNibName:@"catalogCell"  bundle:nil] forCellReuseIdentifier:@"catalogCell" ];
    self.separatorStyle = UITableViewCellSelectionStyleNone;
    self.tableFooterView = [[UIView alloc] init];
    
    // 设置目录标题
    UIView *headerView =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 40)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 100, 20)];
    label.text = @"课程目录";
    label.textColor = [UIColor colorForHex:PINK_COCOR];
    label.font = [UIFont boldSystemFontOfSize:17.0];
    [headerView addSubview:label];
    self.tableHeaderView = headerView;
    
    self.dataSource = self;
    self.delegate = self;
}


#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CatalogCell *cell = [tableView dequeueReusableCellWithIdentifier:@"catalogCell" forIndexPath:indexPath];
    
    cell.noLabel.textColor = [UIColor colorForHex:PINK_COCOR];
    cell.noLabel.text = [NSString stringWithFormat:@"%ld.", indexPath.row +1];
    
    cell.titleLabel.textColor = [UIColor blackColor];
    cell.titleLabel.text = self.dataArr[indexPath.row];
    cell.timeLabel.hidden = YES;
    
    return cell;
}

#pragma mark -- @protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self reloadData];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    CatalogCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.titleLabel.textColor = [UIColor colorForHex:PINK_COCOR];
    
    if(_selDelegate)
        [_selDelegate didSelectbyRow:indexPath.row];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
